<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="7">
        <Card title="分类商品数量（饼图）">
          <PieEchart :pieData="categoryGoodsCount" />
        </Card>
      </el-col>
      <el-col :span="10">
        <Card title="不同城市商品销售">
          <MapEchart :mapData="addressGoodsSale" />
        </Card>
      </el-col>
      <el-col :span="7">
        <Card title="分类商品数量（玫瑰图）">
          <RoseEchart :roseData="categoryGoodsCount" />
        </Card>
      </el-col>
    </el-row>
    <el-row :gutter="20" class="row-content">
      <el-col :span="12">
        <Card title="分类商品的销售">
          <LineEchart :lineData="categoryGoodsSale" />
        </Card>
      </el-col>
      <el-col :span="12">
        <Card title="分类商品的收藏">
          <BarEchart :barData="categoryGoodsFavor" />
        </Card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { useStore } from '@/store'
import Card from '@/base-ui/card'

import {
  PieEchart,
  RoseEchart,
  LineEchart,
  BarEchart,
  MapEchart
} from '@/components/page-echart'

const store = useStore()
store.dispatch('dashboard/getDashboardAction')

const categoryGoodsCount = computed(() => {
  return store.state.dashboard.categoryGoodsCount.map((item: any) => {
    return { name: item.name, value: item.goodsCount }
  })
})

const categoryGoodsSale = computed(() => {
  const xLabels: string[] = []
  const values: any[] = []
  const categoryGoodsSale = store.state.dashboard.categoryGoodsSale
  for (const item of categoryGoodsSale) {
    xLabels.push(item.name)
    values.push(item.goodsCount)
  }
  return { xLabels, values }
})

const categoryGoodsFavor = computed(() => {
  const xLabels: string[] = []
  const values: any[] = []
  const categoryGoodsSale = store.state.dashboard.categoryGoodsFavor
  for (const item of categoryGoodsSale) {
    xLabels.push(item.name)
    values.push(item.goodsFavor)
  }
  return { xLabels, values }
})

const addressGoodsSale = computed(() => {
  return store.state.dashboard.addressGoodsSale.map((item: any) => {
    return { name: item.address, value: item.count }
  })
})
</script>

<style scoped>
.row-content {
  margin-top: 12px;
}
</style>
